
//
//  LXDetailsListCell.m
//  灵秀
//
//  Created by 李田 on 17/3/20.
//  Copyright © 2017年 tianyao. All rights reserved.
//

#import "LXDetailsListCell.h"
#import "LXFoodDetailModel.h"
@interface LXDetailsListCell ()

// icon
@property(nonatomic, weak)UIImageView *iconImageView;
// name
@property(nonatomic, weak)UILabel *nameL;
// 选择数量
@property(nonatomic, weak)UILabel *countL;




@end

@implementation LXDetailsListCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

#pragma mark - 2.0 赋值
- (void)setModel:(LXFoodDetailModel *)model {
    
    _model = model;
    //  图片
    NSString *urlStr = model.picture;
    // 删除尾缀--拓展名
    urlStr = [urlStr stringByDeletingPathExtension];
    NSURL *url = [NSURL URLWithString:urlStr];
    [_iconImageView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"xiaolian"]];
    
    // 菜名
    _nameL.text = model.name;
    
    // 购买数量
    _countL.text = [NSString stringWithFormat:@"已经选择: %zd份", model.buyCount];
}

#pragma mark - 1.0 搭建界面
- (void)setupUI {
    
    //  背景色
    self.contentView.backgroundColor = [UIColor whiteColor];
    
    // 1.icon 图标
    UIImageView *iconImageView = [[UIImageView alloc] init];
    //填充方式--图片不变形
    iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    iconImageView.layer.cornerRadius = 5;
    iconImageView.layer.masksToBounds = YES;
    [self.contentView addSubview:iconImageView];
    
    // 2.菜名
    UILabel *nameL  = [UILabel cz_labelWithText:@"天堂饭" fontSize:13 color:[UIColor blackColor]];
    [self.contentView addSubview:nameL];
    
    // 3.选择数量
    UILabel *countL  = [UILabel cz_labelWithText:@"购买: 4份" fontSize:13 color:[UIColor blackColor]];
    [self.contentView addSubview:countL];
    
    // 关联
    _iconImageView = iconImageView;
    _nameL = nameL;
    _countL = countL;
    
    // 布局
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(5);
        make.left.equalTo(self.contentView);
        make.size.mas_equalTo(CGSizeMake(50, 50));
    }];
    
    [nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(iconImageView.mas_top);
        make.left.equalTo(iconImageView.mas_right).offset(20);
    }];
    
    [countL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(nameL);
        make.top.equalTo(nameL.mas_bottom).offset(10);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
